package sqlanalysisgui.view.model.provider;

import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;

import sqlanalysisgui.view.model.CrudInfo;
import sqlanalysisgui.view.model.TableList;
import sqlanalysisgui.view.model.TableListCrudInfoLineInfoModel;

public class TableListContentProvider implements ITreeContentProvider {

	private TableListCrudInfoLineInfoModel model;
	private static final Object[] EMPTY_ARRAY = new Object[0];

	@Override
	public void dispose() {
	}

	@Override
	public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		this.model = (TableListCrudInfoLineInfoModel) newInput;
	}

	@Override
	public Object[] getElements(Object inputElement) {
		return model.getTableLists().toArray();
/*		if (inputElement instanceof List) {
		} else {
			return EMPTY_ARRAY;
		}*/
	}

	@Override
	public Object[] getChildren(Object parentElement) {
		if (parentElement instanceof TableList) {
			TableList tableLists = (TableList) parentElement;
			return tableLists.getCrudInfos().toArray();
		} else if (parentElement instanceof CrudInfo) {
			CrudInfo crudInfos = (CrudInfo) parentElement;
			return crudInfos.getLineInfos().toArray();
		}
		return EMPTY_ARRAY;
	}

	@Override
	public Object getParent(Object element) {
		return null;
	}

	@Override
	public boolean hasChildren(Object element) {
		if (element instanceof TableList || element instanceof CrudInfo) {
			return true;
		}
		return false;
	}

}
